import { reqCategoryList, reqBannerList, reqFloorList } from '@/api'
// home模块的小仓库
const state = {
    // 数据初始值
    categoryList: [],
    bannerList: [],
    floorList: [],
}
const mutations = {
    CATEGORYLIST(state, categoryList) {
        state.categoryList = categoryList
    },
    BANNERLIST(state, bannerList) {
        state.bannerList = bannerList
    },
    FLOORLIST(state, floorList) {
        state.floorList = floorList
    }
}
const actions = {
    // 通过API里面的接口函数调用，向服务器发请求，获取服务器的数据
    async categoryList({ commit }) {
        let res = await reqCategoryList()
        if (res.code == 200) {
            commit('CATEGORYLIST', res.data)
        }
    },
    // 获取首页轮播图的数据
    async bannerList({ commit }) {
        let res = await reqBannerList()
        if (res.code == 200) {
            commit('BANNERLIST', res.data)
        }
    },
    async floorList({ commit }) {
        let res = await reqFloorList()
        // console.log(res)
        if (res.code == 200) {
            commit('FLOORLIST', res.data)
        }
    }
}
// 计算属性
const getters = {}
export default {
    state,
    mutations,
    actions,
    getters
}